

/*
* Copyright @ 2017 com.iflysse.trains
* crm 下午12:40:33
* All right reserved.
*
*/
	
package com.qf.dao.daoImpl;

import java.util.List;

import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.transaction.annotation.Transactional;

import com.qf.dao.CrmStaffDao;
import com.qf.pojo.CrmStaff;
import com.qf.pojo.CrmStudent;

/**
* @desc: crm
* @descripe:XXXX
* @author: 周锐
* @createTime: 2017年7月25日 下午12:40:33
* @history:
* @version: v1.0

*/
@Transactional(value="txManager")
public class CrmStaffDaoImpl implements CrmStaffDao {
     private HibernateTemplate htl;
     
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmStaffDao#addStaff(com.qf.pojo.CrmStaff)
	*/

	
	/**
	* @param htl the htl to set
	*/
	
	public void setHtl(HibernateTemplate htl) {
	
		this.htl = htl;
	}

	@Override
	public void addStaff(CrmStaff staff) {

		htl.save(staff);

	}

	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmStaffDao#updateStaff(com.qf.pojo.CrmStaff)
	*/

	@Override
	public void updateStaff(CrmStaff staff) {

		htl.update(staff);

	}

	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmStaffDao#crmstaffs()
	*/

	@Override
	public List<CrmStaff> findAllcrmstaffs() {

		
		return htl.getSessionFactory().getCurrentSession().createQuery("from CrmStaff",CrmStaff.class).getResultList();

	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmStaffDao#findbyId(java.lang.Long)
	*/
		
	@Override
	public CrmStaff findbyId(Long staffId) {
		
		//TODO
		return htl.get(CrmStaff.class, staffId);
			
	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmStaffDao#findStaff(java.lang.String)
	*/
		
	
	@Override
	public List<CrmStaff> findStaff(String staffName) {
		
		//TODO
		 return htl.getSessionFactory().getCurrentSession().createQuery("from CrmStaff where staffName=?",CrmStaff.class).setParameter(0,staffName).getResultList();
		
	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmStaffDao#findByName(java.lang.String)
	*/
		
	@Override
	public CrmStaff findByName(String loginName) {
		
		//TODO
		List<CrmStaff> list = htl.getSessionFactory().getCurrentSession().createQuery("from CrmStaff where loginName=?",CrmStaff.class).setParameter(0, loginName).getResultList();
		return list.size()>0?list.get(0):null;
			
	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmStaffDao#addCrmStudent(com.qf.pojo.CrmStudent)
	*/
		

	

}

	